package com.zdd.ehe.controller;

import com.zdd.ehe.EheApplication;
import com.zdd.ehe.entity.FirstTenQuestion;
import com.zdd.ehe.param.QuestionParam;
import com.zdd.ehe.result.Result;
import com.zdd.ehe.service.FirstTenQuestionService;
import com.zdd.ehe.service.KafkaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @version 1.0.0
 * @title: QuestionController
 * @author: HFLy
 * @description:
 * @date: 8/3/2023 上午12:30
 */
@RestController
@Api(tags = "智能问答")
public class QuestionController {
    @Autowired
    private KafkaService kafkaService;
    @Autowired
    private FirstTenQuestionService firstTenQuestionService;
    @PostMapping("/question")
    @ApiOperation("智能问答")
    public Result answer(@RequestBody QuestionParam questionParam){
        String question = questionParam.getQuestion();
        EheApplication.FINISH_QUESTION=false;
        //获取锁
        while (!EheApplication.QUESTION_LOCK){
            EheApplication.PREDICT_LOCK = true;
            kafkaService.sendToQuestion(question);
            while (!EheApplication.FINISH_QUESTION){
                continue;
            }
            EheApplication.QUESTION_LOCK = false;
            break;
        }
        System.out.println(EheApplication.ANSWER);
        return Result.success("识别成功",EheApplication.ANSWER);
    }
    @ApiOperation("前十问题（词云使用）")
    @GetMapping("/firstTenQuestion")
    public Result firstTenQuestion(){
        List<FirstTenQuestion> firstTenQuestionList = firstTenQuestionService.list();
        return Result.success("查询成功",firstTenQuestionList);
    }
}
